$(function () {
    $("#form_shop").bootstrapValidator({
        feedbackIcons: {
            //校验通过时的输入框状态
            valid: 'glyphicon glyphicon-ok',
            //校验失败时的输入框状态
            invalid: 'glyphicon glyphicon-remove',
            //校验中的输入框状态
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            shopname: {
                message: '商户名有误',
                validators: {
                    notEmpty: {
                        message: '商户名不能为空'
                    },
                    stringLength: {
                        min: 1,
                        max: 10
                    }
                }
            },
            division: {
                message: '区域有误',
                validators: {
                    notEmpty: {
                        message: '区域不能为空'
                    },
                    stringLength: {
                        min: 1,
                        max: 10
                    }
                }
            },
            brand: {
                message: '品牌名有误',
                validators: {
                    notEmpty: {
                        message: '品牌名不能为空'
                    },
                    stringLength: {
                        min: 1,
                        max: 10
                    }
                }
            },
            address: {
                message: '地址有误',
                validators: {
                    notEmpty: {
                        message: '地址不能为空'
                    },
                    stringLength: {
                        min: 1,
                        max: 10
                    }
                }
            },

        }
    });
    $("#shopRegister").click(function () {
        if ( $("span:eq(0)").text()=="商户名可用"){
            myGetAjax(
                "/catering_system_app/shopUser/shopUserRegister",
                {
                    shopName:$("#shopname").val(),
                    shopDivision:$("#division").val(),
                    brandName:$("#brand").val(),
                    shopAddress:$("#address").val()
                },
                shopRegister
            )
        }else {
            alert("请输入信息")
        }

    });
    $("#shopname").blur(function () {

        myGetAjax(
            "/catering_system_app/shopUser/checkShop",
            {
                shopName:$("#shopname").val(),
            },
            checkshop
        )
    })
});
function checkshop(RespVo) {
    if (RespVo.code=="100"){
        $("span:eq(0)").attr("style", "color:green");
        $("span:eq(0)").text("商户名可用");
    } else if (RespVo.code=="200"){
        $("span:eq(0)").attr("style", "color:red");
        $("span:eq(0)").text("商户名已存在");
    }
}
function shopRegister(RespVo) {
    if (RespVo.code=="200"){
        alert("注册成功");
        location.href="myShop.html"
    } else {
        alert(RespVo.msg)
    }
}